namespace ETestIT.UI.Presentation.Storage
{
    using System.Web;
    using System.Web.SessionState;

    public class SessionProvider : ISessionProvider
    {
        private HttpSessionState Session
        {
            get { return HttpContext.Current.Session; }
        }

        public T Get<T>(string key)
        {
            if (Session[key] == null)
                return default(T);

            return (T) Session[key];
        }

        public void Set<T>(string key, T value)
        {
            Session[key] = value;
        }

        public string GetString(string key)
        {
            var s = Get<string>(key);
            return s ?? string.Empty;
        }

        public void SetString(string key, string value)
        {
            Set(key, value);
        }

        public bool Contains(string key)
        {
            return Session[key] != null;
        }

        public void Remove(string key)
        {
            if(Contains(key))
                Session.Remove(key);
        }
    }
}